<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="baidu-site-verification" content="code-UjJKh3jtOo">
  <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.0/styles/atom-one-dark.min.css">
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <title>Tit1e</title>
  <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2767111597631391" crossorigin="anonymous"></script>
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="Tit1e" type="application/atom+xml">
</head>

<body class="dark">
    <div class="container">
    <header class="header">
  <div class="title">
      <a href="/" class="logo">Tit1e</a>
      <div class="btn-dark"></div>
      <script>
        let bodyClx = document.body.classList;
        let btnDark = document.querySelector('.btn-dark');
        let sysDark = window.matchMedia('(prefers-color-scheme: dark)');
        let darkVal = localStorage.getItem('dark');

        let setDark = (isDark) => {
        bodyClx[isDark ? 'add' : 'remove']('dark');
        localStorage.setItem('dark', isDark ? 'yes' : 'no');
        };

        setDark(darkVal ? darkVal === 'yes' : sysDark.matches);
        requestAnimationFrame(() => bodyClx.remove('not-ready'));

        btnDark.addEventListener('click', () => setDark(!bodyClx.contains('dark')));
        sysDark.addEventListener('change', (event) => setDark(event.matches));
      </script>
  </div>
    <ul class="menu">
        
        
        
        
        <li class="menu-item ">
            <a href="/" class="menu-item-link">Home</a>
        </li>
        
        
        <li class="menu-item ">
            <a href="/archives/" class="menu-item-link">Archives</a>
        </li>
        
        
        <li class="menu-item ">
            <a href="/atom.xml" class="menu-item-link">RSS</a>
        </li>
        
        
        <li class="menu-item ">
            <a target="_blank" rel="noopener" href="https://pixeltimer.art" class="menu-item-link">Pixel Timer</a>
        </li>
        
    </ul>
    <div class="search-box">
        <input type="search" id="search" placeholder="搜索">
    </div>
</header>
    <article class="post">
  <div class="post-meta">
    <span class="post-time">5 / 12, 2018</span>
  </div>
  <div class="post-title">
    <h1 class="title">Mac 下为 MAMP (Pro) 安装 redis 扩展</h1>
  </div>
  
  <ul class="post-tags">
    
    <li class="tag-item">
      #Mac
    </li>
    
    <li class="tag-item">
      #折腾&#39;
    </li>
    
  </ul>
  
  <div class="post-content">
    <p>Mac 用户一般开本地服务器环境的时候用得比较多的就是 <a target="_blank" rel="noopener" href="https://www.mamp.info/en/">MAMP</a> 这款软件吧，指定目录，一键开启，甚至可以什么都不用配置就可以将服务跑起来。不过前阵子开发的时候，由于公司项目用了 <a target="_blank" rel="noopener" href="https://redis.io/">redis</a> ，但 MAMP 本身的 php 是不带有 redis 插件的，为了装这个东西，我折腾了好几个小时，所以在这里记录一下。</p>
<span id="more"></span>
<h3 id="下载-amp-解压-amp-amp-编译-PHP-源码"><a href="#下载-amp-解压-amp-amp-编译-PHP-源码" class="headerlink" title="下载 &amp; 解压 &amp;&amp; 编译 PHP 源码"></a>下载 &amp; 解压 &amp;&amp; 编译 PHP 源码</h3><p><strong>教程中将以 php 5.5.30 版本作为例子，实际操作中请将版本号做相应替换</strong></p>
<p>为方便下载，我在这放上下载地址，我这里的地址是 5.5.30 的 php 版本，如果需要其他版本，只需将地址中的版本号进行相应替换。<br>下载地址： <a target="_blank" rel="noopener" href="http://us3.php.net/get/php-5.5.30.tar.gz/from/a/mirror">http://us3.php.net/get/php-5.5.30.tar.gz/from/a/mirror</a></p>
<p>下载完成后，将源码解压至 <code>/applications/MAMP/bin/php/php5.5.30/include/php</code></p>
<p>cd 至源码目录，并执行：</p>
<pre><code>cd /applications/MAMP/bin/php/php5.5.30/include/php

./configure
</code></pre>
<p>当前目录下继续操作：</p>
<pre><code>git clone https://github.com/nicolasff/phpredis.git

cd phpredis
</code></pre>
<p>接下来就是进行编译，但为了确保期间，建议在执行下列操作前先执行，除非你很确定你已经安装 <code>autoconf</code><br>通过 <a target="_blank" rel="noopener" href="https://brew.sh/index_zh-cn">Homebrew</a> 安装</p>
<p><code>brew install autoconf</code></p>
<p>下面进行编译<br>注：此时的目录应该为<code>/applications/MAMP/bin/php/php5.5.30/include/php/phpredis</code></p>
<p>执行下列命令：</p>
<pre><code>/Applications/MAMP/bin/php/php5.5.30/bin/phpize

./configure --with-php-config=/Applications/MAMP/bin/php/php5.5.30/bin/php-config

make
</code></pre>
<p>所有命令执行完成之后，会在当前目录下生成一个 <code>modules</code> 文件夹，里面有 <code>redis.so</code>，将这个文件复制至 <code>/Applications/MAMP/bin/php/php5.5.30/lib/php/extensions/no-debug-non-zts-XXXXXXXX</code>（最后的文件夹名每个用户有所差别）。</p>
<p>最后，修改 <code>/Applications/MAMP/bin/php/php5.3.30/conf/php.ini</code>,在文件的 545 行加上 <code>extension=redis.so</code>，保存关闭，重启服务器。</p>
<p>到此，redis 扩展安装完毕。</p>
<h3 id="安装-redis"><a href="#安装-redis" class="headerlink" title="安装 redis"></a>安装 redis</h3><p>安装 redis 就很简单了，一句命令行搞定：</p>
<pre><code>brew install redis
</code></pre>

  </div>
  <div class="post-near">
    
    <a
      class="post-near-prev"
      href="/p/895794e6.html"
      title="webpack 通过 NODE_ENV 判断当前环境"
    >
      <span class="arrow">←</span>
      <span class="post-near-title">
        webpack 通过 NODE_ENV 判断当前环境
      </span>
    </a>
    
    
    <a
      class="post-near-next"
      href="/p/ae13700d.html"
      title="Mac 创建 .htaccess 文件"
    >
      <span class="post-near-title">
        Mac 创建 .htaccess 文件
      </span>
      <span class="arrow">→</span>
    </a>
    
  </div>
</article>

    <footer class="footer">
  <p>本博客采用 <a class="license-link" rel="license noopener" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">署名-非商业性使用-相同方式共享 4.0 国际</a>协议进行许可</p>
  <p>
    <span>Thanks For <a target="_blank" rel="noopener" href="https://github.com/nanxiaobei/hugo-paper" taget="_blank">hugo-paper</a></span>
    <span style="margin-left: 10px;">&copy; 2016-2025 by Tit1e</span>
  </p>
</footer>
    </div>
    <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.0/highlight.min.js"></script>
<script>
  hljs.initHighlightingOnLoad();
  var _hmt = _hmt || [];
    (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?6349d3bc54baea0b04a65145c5e3b799";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
    })();
    const block = document.querySelectorAll('.post-content')[0]
    block.addEventListener('click', e => {
        const {nodeName, src} = e.target
        if(nodeName !== 'IMG') return
        document.body.classList.add('overflow-hidden')
        const div = document.createElement('div')
        div.id = 'global-cover'
        div.title = '点击关闭'
        const a = document.createElement('a')
        a.href = src
        a.target="_blank"
        a.title = '点击打开原图'
        const img = document.createElement('img')
        img.className = 'show-pic'
        img.src = src
        a.appendChild(img)
        div.appendChild(a)
        document.body.appendChild(div)
    })
    document.body.addEventListener('click', e => {
        if(e.target.id === 'global-cover'){
            document.body.classList.remove('overflow-hidden')
            document.body.removeChild(e.target)
        }
    })
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7M04VN3JZ4"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-7M04VN3JZ4');
</script>

<script src="/js/search.js"></script>


</body>
</html>